package com.mjl.shops.fragment;

import android.view.LayoutInflater;
import android.view.View;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.jaeger.library.StatusBarUtil;
import com.mjl.shops.R;
import com.mjl.shops.activity.GoodsDetailsActivity;
import com.mjl.shops.adapter.CollatorLeftAdapter;
import com.mjl.shops.adapter.CollatorRightAdapter;
import com.mjl.shops.base.BaseDate;
import com.mjl.shops.base.BaseFragment;
import com.mjl.shops.bean.CollatorLeftBean;
import com.mjl.shops.bean.CollatorRightBean;
import com.mjl.shops.utils.BannerImageLoaderOneUtils;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class CollatorFragment extends BaseFragment {

    private List<CollatorLeftBean>collatorLeftBeans = new ArrayList<>();

    private List<CollatorRightBean> collatorRightBeans= new ArrayList<>();

    private CollatorLeftAdapter collatorLeftAdapter;

    private CollatorRightAdapter collatorRightAdapter;

    private Banner collator_head_banner;

    private List<Integer> integers = new ArrayList<>();

    @BindView(R.id.left_coll_recycler)
    RecyclerView leftRecycler;

    @BindView(R.id.right_coll_recycler)
    RecyclerView rightRecycler;

    @Override
    protected View initView() {
        StatusBarUtil.setTranslucentForImageView(getActivity(), 10, null);
        StatusBarUtil.setDarkMode(getActivity());
        View mView = View.inflate(getActivity(), R.layout.fragment_collator_layout,null);
        ButterKnife.bind(this,mView);
        collatorLeftBeans.clear();
        collatorLeftBeans.addAll(BaseDate.getCollatorLeftBeans());
        integers.clear();
        integers.addAll(BaseDate.getBanners());
        collatorLeftAdapter = new CollatorLeftAdapter(R.layout.item_collator_left_layout,collatorLeftBeans);
        leftRecycler.setLayoutManager(new LinearLayoutManager(getActivity()));
        leftRecycler.setAdapter(collatorLeftAdapter);
        leftRecycler.addOnItemTouchListener(new OnItemClickListener() {
            @Override
            public void onSimpleItemClick(BaseQuickAdapter adapter, View view, int position) {
                for (int i =0;i<collatorLeftBeans.size();i++){
                    if (i == position){
                        collatorLeftBeans.get(i).setCollatorSelect(1);
                    }else{
                        collatorLeftBeans.get(i).setCollatorSelect(0);
                    }
                }
                collatorLeftAdapter.notifyDataSetChanged();
            }
        });
        collatorRightBeans.clear();
        collatorRightBeans.addAll(BaseDate.getCollatorRightBeans());
        collatorRightAdapter = new CollatorRightAdapter(collatorRightBeans);
        rightRecycler.setLayoutManager(new LinearLayoutManager(getActivity()));
        rightRecycler.setAdapter(collatorRightAdapter);
        rightRecycler.addOnItemTouchListener(new OnItemClickListener() {
            @Override
            public void onSimpleItemClick(BaseQuickAdapter adapter, View view, int position) {
                if (collatorRightBeans.get(position).getItemType() == 1){
                    GoodsDetailsActivity.StartIntent(getActivity());
                }
            }
        });
        View headView = LayoutInflater.from(getActivity()).inflate(R.layout.banner_layout,null,false);
        collatorRightAdapter.addHeaderView(headView);
        collator_head_banner = headView.findViewById(R.id.collator_head_banner);
        collator_head_banner.setBannerStyle(BannerConfig.RIGHT);
        collator_head_banner.setImages(integers);
        collator_head_banner.setDelayTime(3000);
        collator_head_banner.setImageLoader(new BannerImageLoaderOneUtils());
        collator_head_banner.isAutoPlay(true);
        collator_head_banner.setIndicatorGravity(BannerConfig.RIGHT);
        collator_head_banner.start();
        return mView;
    }

    @Override
    protected void setData(View view) {

    }

    @Override
    protected void initData() {

    }
}
